import React from "react";
class ErrorBoundary extends React.Component{
    state = { error: null }

    componentDidCatch(error, info) {
        // Display fallback UI
        this.setState({ error })
        // You can also log the error to an error reporting service
        console.log('捕获到错误', error, info)
    }

    render() {
        if (this.state.error) {
            return <div>我是备用ui</div>
        }

        return this.props.children
    }
}